package cn.edu.bjut.homework.chapter5;

import cn.edu.bjut.homework.chapter3.Date;
import cn.edu.bjut.homework.chapter4.*;

import java.util.LinkedHashSet;
import java.util.Set;

public class Patent {
    protected int id;
    protected Date date;
//    protected Ipc[] ipcs;
//    protected Cpc[] cpcs;
    protected Set<Ipc> ipcs;
    protected Set<Cpc> cpcs;
    protected char position;
    protected char value;

    public Patent(int id, String date, String ipcs, String cpcs, char position, char value) {
        this.id = id;
        this.date = new Date(date);
        this.position = position;
        this.value = value;
        this.ipcs = new LinkedHashSet<>();
        this.cpcs = new LinkedHashSet<>();

        String[] ipc = ipcs.split("\\s*,\\s*");
        for (String s : ipc) {
            this.ipcs.add(new Ipc(s));
        }

        String[] cpc = cpcs.split("\\s*,\\s*");
        for (String s : cpc) {
            this.cpcs.add(new Cpc(s, position, value));
        }
    }

    public int getId() {
        return id;
    }

    public Date getDate() {
        return date;
    }

    public Set<Ipc> getIpcs() {
        return ipcs;
    }

    public Set<Cpc> getCpcs() {
        return cpcs;
    }

    @Override
    public String toString() {
        return "Patent{" +
                "id=" + id +
                ", date=" + date +
                ", ipcs=" + ipcs +
                ", cpcs=" + cpcs +
                ", position=" + position +
                ", value=" + value +
                '}';
    }
}
